//
//  imageLabel.m
//  Products_B
//
//  Created by lanou on 16/5/29.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "imageLabel.h"
#import <UIImageView+WebCache.h>
@interface imageLabel ()

@property (nonatomic, strong) UILabel *textLabel1;
@property (nonatomic, strong) UILabel *textLabel2;

@property(nonatomic,strong)UIImageView *topImageView;

@property(nonatomic,assign)int index;

@end

@implementation imageLabel

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame image:(NSString *)imageUrl text:(NSString *)textString1 text2:(NSString *)textString2 index:(int)index tapAction:(TapBlock)tapBlock{
    
    static int count = 0;
    if (count != 0) {
        count ++;
    }
    
    self.index  = index;
   
    CGRect newFrame = frame;
    newFrame.size.height = newFrame.size.width + 80;
    if (self = [super initWithFrame:newFrame]) {
        self.tapBlock = tapBlock;
        self.topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, newFrame.size.width, newFrame.size.width)];
        self.topImageView.layer.cornerRadius = 45;
        self.topImageView.layer.masksToBounds = YES;
        if (imageUrl) {
            [_topImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
        }
        [self addSubview:_topImageView];
        
        _textLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0,newFrame.size.width + 10, newFrame.size.width, 25)];
        if (textString1) {
            _textLabel1.text = textString1;
        }
        _textLabel1.font = [UIFont systemFontOfSize:15];
        _textLabel1.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_textLabel1];
      
        _textLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(0,newFrame.size.width + 20 + 25, newFrame.size.width, 25)];
        if (textString2) {
            _textLabel2.text = [NSString stringWithFormat:@"粉丝：%@",textString2];
        }
        _textLabel2.textAlignment = NSTextAlignmentCenter;

        _textLabel2.font = [UIFont systemFontOfSize:14];
        [self addSubview:_textLabel2];

        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)tapAction:(UITapGestureRecognizer *)sender{
    if (self.tapBlock) {
        self.tapBlock(_index);
    }
}

- (void)setImageLabelText:(NSString *)text1 labelText:(NSString *)text2{
    _textLabel1.text = text1;
    _textLabel2.text = text2;
}

-(void)setImageLabelView:(UIImage *)image{
    
    _topImageView.image = image;
}

-(void)setImageLabelWithUrling:(NSString *)imageUrl{
    
    [_topImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
}



@end
